package com.wynn.dao;


import com.wynn.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface UserDao {

    //    根据用户名和密码查询用户
    @Select("select * from user where login_name=#{username} and password=#{password}")
    public User findByUsernameAndPassword(@Param("username") String username, @Param("password") String password);

    //    更新登录时间和ip地址
    @Update("update user set loginDate=#{date},loginIp=#{ip} where login_name=#{login_name}")
    int updateUserLoginDateAndIp(@Param("date") Long date,@Param("ip") String ip,@Param("login_name")String login_name);

    @Select("select * from user where login_name=#{username}")
    User findByName(String username);

    @Select("select r.id,roleName from user u,role r,user_role ur where u.login_name=#{username} and u.id=ur.userId and " +
            "ur.roleId = r.id")
    List<Map<String, String>> getUserRoleByUname(String username);

    @Select("select permName from permission p,role_perm pr where pr.roleId=#{id} and pr.pId=p.id")
    List<String> getPermByRid(int id);

    @Insert("insert into notice values(null,#{head},#{content},#{date})")
    void addNotice(@Param("head") String head,@Param("content") String content,@Param("date")  Date date);

    @Select("select head,content from notice order by id desc")
    List<Map<String, String>> selectNotices();
}
